<?php

  class CMovie {
  	
  	static function IsValidMimeType($szVideoFileName, $szVideoFileType, &$szVideoFileExt = '') {
      $aVideoMimeTypes = array('video/3gpp', 'video/3gpp2', 'video/3gpp-tt', 'video/mpeg', 'video/mp4', 'video/mpeg4-generic', 'application/octet-stream');
      
  	  if ( !in_array($szVideoFileType, $aVideoMimeTypes) ) return false;
  	  
  	  //rozszerzenie pliku
  	  $iDotPos = strrpos($szVideoFileName, '.');
  	  if ($iDotPos !== false) $szVideoFileExt = substr($szVideoFileName, $iDotPos+1);
  	  else $szVideoFileExt = '';
  	  
  	  if ( $szVideoFileType == 'application/octet-stream' && $szVideoFileExt != 'flv' ) return false;
  	  
  	  return true;
  	}
    
  	static function Convert2Flv($szInputFileName, $szOutpuFileName, &$mResults, &$iMovieWidth = '', &$iMovieHeight = '', &$iFrameRate = '', &$iSoundQuality = '', &$iBitrate = '') {
      $szCommand = 'ffmpeg -i '.$szInputFileName.' -acodec mp3';

      if ($iBitrate != '') $szCommand .= ' -ab '.$iBitrate;
      else $szCommand .= ' -ab 64';
      
      if ($iSoundQuality != '') $szCommand .= ' -ar '.$iSoundQuality;
      else $szCommand .= ' -ar 22050';
      
      if ($iMovieWidth != '' && $iMovieHeight != '') 
        $szCommand .= ' '.$iMovieWidth.'x'.$iMovieHeight;
      else
        $szCommand .= ' -s 352x288';
      
      $szCommand .= ' -b 350000';
      
      if ($iFrameRate != '') $szCommand .= ' -r '.$iFrameRate;
      else $szCommand .= ' -r 20';
      
      $szCommand .= ' -f flv '.$szOutpuFileName.'.flv';
      
      //die();
      $output = exec($szCommand, $mResults);
  	}
  	
    static function flvTakeShot($szInputFileName, $szOutpuFileName, &$mResults, &$iPicWidth = '', &$iPicHeight = '') {
      $szCommand = 'ffmpeg -i '.$szInputFileName;

      if ($iPicWidth != '' && $iPicHeight != '') 
        $szCommand .= ' -s '.$iPicWidth.'x'.$iPicHeight;
      else
        $szCommand .= ' -s 352x288';
        
      $szCommand .= ' -vframes 80 -f mjpeg '.$szOutpuFileName.'.jpg';
      
      //echo '<pre>Wycinanie 80 klatki: '.$szCommand.'</pre>';
      
      exec($szCommand, $mResults);
  	}
    
  }
  
?>